<template>
  <div class="anniversary-card card-item"
       @click="selectDateCardClick">
    <div class="left-container">
      <span class="title">{{ props.dateItem.title }}</span>
      <div class="content">
        <span class="date">{{ props.dateItem.date }}</span>
        <el-tag v-if="props.dateItem.category"
                type="primary">{{ props.dateItem.category }}
        </el-tag>
      </div>
    </div>

    <div class="right-container"
         :style="{'background-color': props.dateItem?.type === 'countUp'
                  ? 'var(--el-color-success)'
                  : 'var(--el-color-primary)'}">
      <span class="title">{{ props.dateItem.type === 'countUp' ? '已经' : '还有' }}</span>
      <div class="date">
        <span class="value">{{ getAnniversaryRemainDays(props.dateItem) }}</span>
        <span class="unit">天</span>
      </div>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { defineProps, PropType } from 'vue'
import { useRouter } from 'vue-router'
import { useAnniversaryStore } from '@/store/anniversary.ts'
import { IAnniversary } from '@/types/anniversary.ts'
import { getAnniversaryRemainDays } from '@/utils/home/anniversaryUtil.ts'

const router = useRouter()
const anniversaryStore = useAnniversaryStore()

const props = defineProps({
  dateItem: {
    required: true,
    type: Object as PropType<IAnniversary>
  }
})

const selectDateCardClick = async () => {
  anniversaryStore.anniversaryApiType = 'UPDATE'

  if (props.dateItem?.category !== '节假日') {
    anniversaryStore.currentAnniversary = props.dateItem as IAnniversary
    const { id } = anniversaryStore.currentAnniversary
    await router.push({ name: 'AnniversaryDetailId', params: { id } })
  }
}
</script>

<style scoped lang="scss">
.anniversary-card {
  position: relative;
  padding-left: 5px;
  display: grid;
  grid-template-columns: 1fr 100px;

  .left-container {
    padding: 10px;

    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 5px;

    .title {
      font-weight: bold;
      font-size: 1.2rem;
    }

    .content {
      display: flex;
      align-items: center;
      gap: 5px;

      .date {
        color: #696969;
      }
    }
  }

  .right-container {
    padding: 10px;
    border-radius: 0 10px 10px 0;
    color: #FFFFFF;

    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: center;
    gap: 5px;

    .title {
      font-size: 1.2rem;
    }

    .date {
      .value {
        font-size: 1.8rem;
        margin-right: 5px;
      }
    }
  }
}
</style>
